`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date:    19:41:38 11/24/2012 
// Design Name: 
// Module Name:    knight_unit 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
module knight_unit(input [9:0]pixel_x_i,
					  input [9:0]pixel_y_i,
	              input [9:0]pos_x,
	              input [9:0]pos_y,
					  input color,//1 = blanco, 0 = negro
					  output [7:0]knight_rgb_o,
	              output knight_on_o);


	wire [7:0] rom_addr;
	wire [8:0] rom_col;
	reg [59:0] rom_data;
		
	// Parametros constantes de posicion y tamano
	localparam SQUARE_SIZE = 60;
	
	always @*
	case (rom_addr)
		8'h03: rom_data = 60'b000000000000000000000000000100000000000000000000000000000000;
		8'h04: rom_data = 60'b000000000000000000000100000110000000000000000000000000000000;
		8'h05: rom_data = 60'b000000000000000000000110000111000000000000000000000000000000;
		8'h06: rom_data = 60'b000000000000000000001111001111100000000000000000000000000000;
		8'h07: rom_data = 60'b000000000000000000001111111111110000000000000000000000000000;
	   8'h08: rom_data = 60'b000000000000000000001111111111111000000000000000000000000000;
		8'h09: rom_data = 60'b000000000000000000011111111111111000000000000000000000000000;
		8'h0a: rom_data = 60'b000000000000000000111111111111111100000000000000000000000000;
		8'h0b: rom_data = 60'b000000000000000001111111111111111100000000000000000000000000;
		8'h0c: rom_data = 60'b000000000000000011111111111111111110000000000000000000000000;
		8'h0d: rom_data = 60'b000000000000000011111111111111111111000000000000000000000000;
		8'h0e: rom_data = 60'b000000000000000011111111111111111111100000000000000000000000;
		8'h0f: rom_data = 60'b000000000000000111111000111111111111111000000000000000000000;
		8'h10: rom_data = 60'b000000000000000111111000111111111111111000000000000000000000;
		8'h11: rom_data = 60'b000000000000001111111111111111111111111100000000000000000000;
		8'h12: rom_data = 60'b000000000000001111111111111111111111111110000000000000000000;
		8'h13: rom_data = 60'b000000000000001111111111111111111111111111000000000000000000;
		8'h14: rom_data = 60'b000000000000001111111111111111111111111111100000000000000000;
		8'h15: rom_data = 60'b000000000000011111111111111111111111111111110000000000000000;
		8'h16: rom_data = 60'b000000000000011111111111111111111111111111111000000000000000;
		8'h17: rom_data = 60'b000000000000111111111111111111111111111111111000000000000000;
		8'h18: rom_data = 60'b000000000000111111111111111111111111111111111000000000000000;
		8'h19: rom_data = 60'b000000000001111111111111111111111111111111111100000000000000;
		8'h1a: rom_data = 60'b000000000011111111111110000000111111111111111100000000000000;
		8'h1b: rom_data = 60'b000000000011111111111100000000011111111111111100000000000000;
		8'h1c: rom_data = 60'b000000000011111111111000000000011111111111111100000000000000;
		8'h1d: rom_data = 60'b000000000111111111111000000000001111111111111110000000000000;
		8'h1e: rom_data = 60'b000000000111111111110000000000001111111111111110000000000000;
		8'h1f: rom_data = 60'b000000001100111111100000000000011111111111111111000000000000;
		8'h20: rom_data = 60'b000000001111111111000000000001111111111111111111000000000000;
		8'h21: rom_data = 60'b000000001111111110000000000011111111111111111111000000000000;
		8'h22: rom_data = 60'b000000001111111100000000000111111111111111111111000000000000;
		8'h23: rom_data = 60'b000000001111110000000000001111111111111111111110000000000000;
		8'h24: rom_data = 60'b000000000000000000000000011111111111111111111110000000000000;
		8'h25: rom_data = 60'b000000000000000000001111111111111111111111111111000000000000;
		8'h26: rom_data = 60'b000000000000000000111111111111111111111111111110000000000000;
		8'h27: rom_data = 60'b000000000000000011111111111111111111111111111111000000000000;
		8'h28: rom_data = 60'b000000000000000111111111111111111111111111111111000000000000;
		8'h29: rom_data = 60'b000000000000001111111111111111111111111111111111000000000000;
		8'h2a: rom_data = 60'b000000000000011111111111111111111111111111111111000000000000;
		8'h2b: rom_data = 60'b000000000000111111111111111111111111111111111111000000000000;
		8'h2c: rom_data = 60'b000000000000111111111111111111111111111111111111000000000000;
		8'h2d: rom_data = 60'b000000000000111111111111111111111111111111111111000000000000;
		8'h2e: rom_data = 60'b000000000000111111111111111111111111111111111111000000000000;
		8'h2f: rom_data = 60'b000000000000111111111111111111111111111111111111000000000000;
		default: 
				rom_data = 60'b000000000000000000000000000000000000000000000000000000000000;
	endcase
	
	// Asignacion de posicion de imagen contenida en memoria en realacion a posicion
	// actual de pixeles en X y Y
	assign rom_addr = pixel_y_i[7:0] - pos_y[7:0];
	assign rom_col = pos_x[7:0] - pixel_x_i[7:0];	
	assign rom_bit = rom_data[rom_col];
	
	assign sq_knight_on = (pixel_x_i >= pos_x) && (pixel_x_i <= (pos_x+SQUARE_SIZE)) &&
							  (pixel_y_i >= pos_y) && (pixel_y_i <= (pos_y+SQUARE_SIZE));
						  
	assign knight_on_o = sq_knight_on && rom_bit;
	
	assign knight_rgb_o = (color)? 8'b11101110 : 8'b10011001;//color = 1 es lila., color =0 es azul
endmodule
